const app = getApp()
const http = require("../../../utils/http.js")

Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    Custom: app.globalData.Custom,
    TabCur: 0,
    VerticalNavTop: 0,
    list: [],
    poilist: [],

    load: true
  },
  onLoad(options) {
    wx.showLoading({
      title: '加载中...',
      mask: true
    });
    let that = this
    http.get("/mdd/getAll")
      .then(res => {
        that.setData({
          list: res.data.data
        })
        if (options.mddId != null) {
          let mddList = res.data.data
          let mddIndex = mddList.findIndex((item) => {
            return item.mddId === options.mddId
          })
          that.setData({
            TabCur: mddIndex,
            VerticalNavTop: (mddIndex - 1) * 50
          })
        }
        http.post("/poi/getPois", {
          mddId: res.data.data[that.data.TabCur].mddId
        }).then(poires => {
          that.setData({
            poilist: poires.data.data
          })
          wx.hideLoading()
        })
      })
  },
  onReady() {

  },
  tabSelect(e) {
    let that = this
    that.setData({
      TabCur: e.currentTarget.dataset.id,
      VerticalNavTop: (e.currentTarget.dataset.id - 1) * 50
    })

    http.post("/poi/getPois", {
      mddId: that.data.list[e.currentTarget.dataset.id].mddId
    }).then(poires => {
      that.setData({
        poilist: poires.data.data
      })
    })
  },
  toPoiDetail(e) {
    let poiId = e.currentTarget.dataset.poiid
    wx.navigateTo({
      url: '/pages/location/poidetail/poidetail?poiId=' + poiId,
    })
  }
})